package com.bohua.Car.admin.service.Impl;

import com.bohua.Car.admin.common.Lay;
import com.bohua.Car.admin.common.Msg;
import com.bohua.Car.admin.common.Pie;
import com.bohua.Car.admin.dao.CarsMapper;
import com.bohua.Car.admin.entity.Cars;
import com.bohua.Car.admin.entity.Customers;
import com.bohua.Car.admin.service.CarsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@Service
public class CarsServiceImpl implements CarsService {
    @Resource
    private CarsMapper carsMapper;

    @Override
    public Msg addCars(Cars cars)
    {
        int i=carsMapper.insert(cars);
        Msg msg=new Msg();
        if(i>0){
            msg.setMsg("添加成功");
        }else {
            msg.setCode(-1);
            msg.setMsg("添加失败");
        }
        return msg;
    }

    @Override
    public Msg updateCars(Cars cars) {
        int i=carsMapper.updateByPrimaryKey(cars);
        Msg msg=new Msg();
        if(i>0){
            msg.setMsg("修改成功");
        }else {
            msg.setCode(-1);
            msg.setMsg("修改失败");
        }
        return msg;
    }

    @Override
    public Msg delCars(Cars cars) {
        int i=carsMapper.deleteByPrimaryKey(cars.getId());
        Msg msg=new Msg();
        if(i>0){
            msg.setMsg("删除成功");
        }else {
            msg.setCode(-1);
            msg.setMsg("删除失败");
        }
        return msg;
    }

    @Override
    public Lay getAll(Cars cars, Integer page, Integer limit) {
        //进行分页
        PageHelper.startPage(page,limit);
        List<Cars> car=carsMapper.getAll(cars);
        PageInfo info=new PageInfo(car);
        Lay lay = new Lay();
        lay.setPage(page);
        lay.setCount(info.getTotal());
        lay.setData(info.getList());
        lay.setLimit(limit);
        return lay;
    }

    @Override
    public List<Cars> getselect (Cars cars) {
        return (List<Cars>) carsMapper.selectByPrimaryKey(cars.getId());
    }

    @Override
    public List<Pie> Pie() {
        return carsMapper.Pie();
    }


}
